﻿
@{
    ViewBag.Title = "订单信息";
    var order = ViewBag.Order as CubicFWNet.Data.ViewModal.OrderInfo;
    var opList = ViewBag.OpList as IEnumerable<CubicFWNet.Data.ViewModal.ProductView>;
}



<section class="content-header">
    <h1>
        订单信息
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active">订单信息</li>
    </ol>
</section>

<section class="content">
    <form class="form-horizontal" method="post" id="formMain">
        <div class="box box-solid">
            <div class="box-body">
                <div class="row">
                    <input type="hidden" name="OrderID" id="OrderID" value="@order.Id" />
                    <input type="hidden" name="ProData" id="ProData" />
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="CusName" class="col-sm-3 control-label">客户名称</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="CusName" name="CusName" value="@order.CustomerName" readonly />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="InitPrice" class="col-sm-3 control-label">订单总价</label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" id="Price" name="Price" value="@ViewBag.Price" readonly />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Number" class="col-sm-3 control-label">内部订单号</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Number" name="Number" value="@ViewBag.Number" readonly/>
                        </div>
                    </div>


                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Number" class="col-sm-3 control-label">客户订单号</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="CusNumber" name="CusNumber" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Delivery" class="col-sm-3 control-label">发货方式</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Delivery" name="Delivery" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12" style="display:none">
                        <label for="Channel" class="col-sm-3 control-label">订货途径</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Channel" name="Channel" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="SendTime" class="col-sm-3 control-label">希望交货期</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control Timedatepicker" id="SendTime" name="SendTime" />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Number" class="col-sm-3 control-label">选择工序</label>
                        <div class="col-sm-9">
                            <label class="radio-inline"><input type="radio" name="IsWork" value="1" checked />生产分配</label>&nbsp;&nbsp;&nbsp;
                            <label class="radio-inline"><input type="radio" name="IsWork" value="2" />转库存</label>
                        </div>
                    </div>

                </div>

                <div id="divProList">
                    @foreach (var item in opList)
                    {
                
                        <div class="row panelLayout" id="@item.Id" >
                            <input type="hidden" class="OPID" value="@item.OrderProductID" />
                            <div class="form-group col-md-6 col-sm-12">
                                <label for="CusName" class="col-sm-3 control-label">产品名称</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" value="@item.Name" readonly />
                                </div>
                            </div>

                            <div class="form-group col-md-6 col-sm-12">
                                <label for="CusName" class="col-sm-3 control-label">产品数量</label>
                                <div class="col-sm-9">
                                    <input type="number" class="form-control Amount" value="@item.Amount" min="0" onblur="GetOrderPrice()" />
                                </div>
                            </div>

                            <div class="form-group col-md-6 col-sm-12">
                                <label for="CusName" class="col-sm-3 control-label">参考价</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" value="@item.Price" readonly />
                                </div>
                            </div>

                            <div class="form-group col-md-6 col-sm-12">
                                <label for="CusName" class="col-sm-3 control-label">最终价</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control Price" value="@item.FinalPrice" readonly />
                                </div>
                            </div>

                        </div>
                    }
                </div>
                <div class="row">
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Memo" class="col-sm-3 control-label">备注</label>
                        <div class="col-sm-9">
                            <textarea rows="3" class="form-control" id="Memo" name="Memo"></textarea>
                        </div>
                    </div>
                </div>
                <div class="row">

                </div>
            </div>
            <div class="box-footer">
                <div class="box-footer">
                    <span class="btn btn-primary " onclick="FormSub()" id="btnOk">确 定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a class="btn btn-primary" href="@Url.Action("ApplyList","Order")">返 回</a>&nbsp;&nbsp;&nbsp;&nbsp;
                    <label class="danger">@ViewBag.Info</label>
                    <div class="text-red" style="margin-top:20px;font-weight:bold">下一步：采购管理-->生产计划分配</div>
                </div>
            </div>
        </div>
    </form>
</section>
@section Scripts {
<script>
    //日期控件
    $("#SendTime").datepicker({
        autoclose: true,
        language: 'zh', //汉化
        format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
        minView: "month"//选择日期后，不会再跳转去选择时分秒
    })

    //计算订单总价
    GetOrderPrice();

    //提交数据
    function FormSub() {

        //验证订单号
        var number = $("#CusNumber").val().trim();
        if (number == "") {
            $.modalAlert("请输入客户订单号", "warning");
            return false;
        }
        
        //交货期
        var sendTime = $("#SendTime").val().trim();
        if (sendTime == "") {
            $.modalAlert("请输入交货期", "warning");
            return false;
        }

        //获取产品列表
        var proList = $("#divProList .panelLayout");
        var prodata = [];
        var num = proList.size();
        if (num <= 0)
        {
            $.modalAlert("请选择产品！", "warning");
            return false;
        }

        for (i = 0; i < num; i++) {
            var id = proList.eq(i).attr("id");
            var opid = $("OPID").eq(i).val();
            var amount = $(".Amount").eq(i).val();
            if (amount == "" || amount <= 0 || amount>10000000) {
                $.modalAlert("请输入正确产品数量！", "warning");
                return false;
            }
            prodata.push({OPID:opid, ProductID: id, Amount: amount });
        }

        $("#ProData").val(JSON.stringify(prodata));
        $("#btnOk").attr('disabled', "true")
        $("#formMain").submit();
    }

    //获取订单总价
    function GetOrderPrice() {
        //获取产品列表
        var proList = $("#divProList .panelLayout");
        var prodata = [];
        var num = proList.size();
        var total = 0;

        for (i = 0; i < num; i++) {
            var id = proList.eq(i).attr("id");
            var amount = $(".Amount").eq(i).val();
            var price = $(".Price").eq(i).val();
            if (amount == "" || amount <= 0 || amount >= 10000000) {
                $.modalAlert("请输入正确产品数量！", "warning");
                return false;
            }

            total+=(amount*price);
            $("#Price").val(total);
        }
    }


</script>
}